﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm;
using VK.Casemeet.TravelLogs;
using VK.Casemeet.Merchants;

namespace VK.Casemeet.Web.ShopAdmin.TravelLogs
{
    public partial class TravelLogAdd : System.Web.UI.Page
    {
        public string logo = "null.jpg";

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="游记日志",Url="/ShopAdmin/TravelLogs/TravelLogList.aspx"},
                new MapPath{ Text="新建日志",Url="#"}
            };

            if (!IsPostBack)
            {
                txtCreated.Text = DateTime.Now.ToString();
                lbEditor.Text = AdminBLL.GetSessionAdmin().Account;
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            TravelLogEntity travelLog = LoadEntity();

            if (TravelLogBLL.InsertTravelLog(travelLog) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                txtCreated.Text = DateTime.Now.ToString();
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected TravelLogEntity LoadEntity()
        {
            TravelLogEntity travelLog = new TravelLogEntity();
            travelLog.ObjectID = AdminBLL.GetSessionAdmin().ShopID;
            travelLog.ObjectType = 1;
            travelLog.Title = txtTitle.Text;
            travelLog.Content = Server.HtmlEncode(Util.GetFormString("txtContent"));
            travelLog.IsEnable = true;
            travelLog.Created = Util.ConverDateTime(txtCreated.Text);
            travelLog.Updated = Util.ConverDateTime(txtCreated.Text);
            travelLog.Sort = 0;
            travelLog.Hits = 0;
            travelLog.Editor = lbEditor.Text;

            return travelLog;
        }
    }
}